package verify

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
)

func hmacSHA256(key, data []byte) []byte {
	mac := hmac.New(sha256.New, key)
	mac.Write([]byte(data))
	return mac.Sum(nil)
}

func Signature(secret, data []byte) string {
	return hex.EncodeToString(hmacSHA256([]byte(secret), data))
}

func ValidateSignature(secret, signatrue string, data []byte) bool {
	serverSign := Signature([]byte(secret), data)
	return hmac.Equal([]byte(serverSign), []byte(signatrue))
}
